package soundAnalyze;


import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;


public class paint extends JPanel{

	private float scalingFactor = 1;

	
	final Color color = Color.red;
	float[] samples;
	int samplesPerPixel=1;
	int width=1024, height=512;

	public paint(float[] samples){
		this.samples=samples;
		repaint();

	}

	public void paintComponent(Graphics g){
		super.paintComponent(g);
		
		g.setColor( Color.black );
		g.fillRect( 0, 0, 512, 512); 
		
		float min = 0;
		float max = 0;
		for( int i = 0; i < samples.length; i++ )
		{
			min = Math.min( samples[i], min );
			max = Math.max( samples[i], max );
		}
		scalingFactor = max - min;
		
		g.setColor( color );
		float lastValue = (samples[0] / scalingFactor) * height / 3 + height / 2;
		for( int i = 1; i < samples.length; i++ )
		{
			float value = (samples[i] / scalingFactor) * height / 3 + height / 2;
			g.drawLine( (int)((i-1) / samplesPerPixel), height - (int)lastValue, (int)(i / samplesPerPixel), height - (int)value );
			lastValue = value;
			
		}
		
	}
	
	
	public void Repaint(float[] f){
		samples=f;
		repaint();
	}


}

